package com.itheima.controller;


import com.itheima.common.R;
import com.itheima.domain.SmsHomeAdvertise;
import com.itheima.service.SmsHomeAdvertiseService;
import com.itheima.util.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")

public class  SmsHomeAdvertiseController {


    @DubboReference
    private SmsHomeAdvertiseService advertiseService;

    @GetMapping("/home/advertise/list")
    public R list(Integer name, String type, Integer pageNum, Integer pageSize, String endTime) {
        PageBeanVo pageBeanVo = advertiseService.list(endTime, name, pageNum, pageSize, type);
        return R.success(pageBeanVo);
    }

    @PostMapping("/home/advertise/create")
    public R add(@RequestBody SmsHomeAdvertise advertise) {
        advertiseService.add(advertise);
      return R.success("添加成功");
    }

    @PostMapping("/home/advertise/delete")
    public R delete(Integer [] ids) {
         advertiseService.delete(ids);
        return R.success("删除成功");
    }

    @PostMapping("/home/advertise/update/status/{id}")
    public R updateStatus(Integer id, Integer status) {
        advertiseService.updateStatus(id, status);

            return R.success("修改成功");

    }

    @PostMapping("/home/advertise/update/{id}")
    public R updateById(@RequestBody SmsHomeAdvertise advertise, @PathVariable Integer id) {
      advertiseService.updateById(advertise,id);
            return R.success("修改成功");

    }

    @GetMapping("/home/advertise/{id}")
    public R findById(@PathVariable Integer id) {
        SmsHomeAdvertise advertise = advertiseService.findById(id);
        return R.success(advertise);
    }
}
